package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocResidenceDao;
import com.irdstudio.cdp.pboc.service.domain.PbocResidence;
import com.irdstudio.cdp.pboc.service.facade.PbocResidenceService;
import com.irdstudio.cdp.pboc.service.vo.PbocResidenceVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 居住信息				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocResidenceService")
public class PbocResidenceServiceImpl implements PbocResidenceService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocResidenceServiceImpl.class);

	@Autowired
	private PbocResidenceDao pbocResidenceDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocResidence(PbocResidenceVO inPbocResidenceVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocResidenceVo.toString());
		int num = 0;
		try {
			PbocResidence pbocResidence = new PbocResidence();
			beanCopy(inPbocResidenceVo, pbocResidence);
			num = pbocResidenceDao.insertPbocResidence(pbocResidence);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocResidenceVO inPbocResidenceVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocResidenceVo);
		int num = 0;
		try {
			PbocResidence pbocResidence = new PbocResidence();
			beanCopy(inPbocResidenceVo, pbocResidence);
			num = pbocResidenceDao.deleteByPk(pbocResidence);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocResidenceVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocResidenceVO inPbocResidenceVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocResidenceVo.toString());
		int num = 0;
		try {
			PbocResidence pbocResidence = new PbocResidence();
			beanCopy(inPbocResidenceVo, pbocResidence);
			num = pbocResidenceDao.updateByPk(pbocResidence);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocResidenceVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocResidenceVO queryByPk(PbocResidenceVO inPbocResidenceVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocResidenceVo);
		try {
			PbocResidence queryPbocResidence = new PbocResidence();
			beanCopy(inPbocResidenceVo, queryPbocResidence);
			PbocResidence queryRslPbocResidence = pbocResidenceDao.queryByPk(queryPbocResidence);
			if (Objects.nonNull(queryRslPbocResidence)) {
				PbocResidenceVO outPbocResidenceVo = beanCopy(queryRslPbocResidence, new PbocResidenceVO());
				logger.debug("当前查询结果为:"+ outPbocResidenceVo.toString());
				return outPbocResidenceVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocResidenceVO> queryAllOwner(PbocResidenceVO pbocResidenceVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocResidenceVO> list = null;
		try {
			List<PbocResidence> pbocResidences = pbocResidenceDao.queryAllOwnerByPage(pbocResidenceVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocResidences.size());
			pageSet(pbocResidences, pbocResidenceVo);
			list = (List<PbocResidenceVO>) beansCopy(pbocResidences, PbocResidenceVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocResidenceVO> queryAllCurrOrg(PbocResidenceVO pbocResidenceVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocResidence> pbocResidences = pbocResidenceDao.queryAllCurrOrgByPage(pbocResidenceVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocResidences.size());
		List<PbocResidenceVO> list = null;
		try {
			pageSet(pbocResidences, pbocResidenceVo);
			list = (List<PbocResidenceVO>) beansCopy(pbocResidences, PbocResidenceVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocResidenceVO> queryAllCurrDownOrg(PbocResidenceVO pbocResidenceVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocResidence> pbocResidences = pbocResidenceDao.queryAllCurrDownOrgByPage(pbocResidenceVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocResidences.size());
		List<PbocResidenceVO> list = null;
		try {
			pageSet(pbocResidences, pbocResidenceVo);
			list = (List<PbocResidenceVO>) beansCopy(pbocResidences, PbocResidenceVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
}
